v[50];s;m;t;
main(n,i,o,u,a)
{
	for(gets(v);~scanf("%d%d%d",&n,&s,&m);)
	{
		for(i=n;i;scanf("%d",v+--i));

		for(a=0,t=m;i<n&!a;i++)
		{
			o=t+v[i]>m;
			u=t-v[i]<0;

			if(o)t-=v[i];
			if(u)t+=v[i];

			a=o&u;
		}
		printf("%d %d\n",a,t);
	}
}
